<?php
require('setup.inc.php');
require(constant('SYSROOT') . 'points_add.c.php');
$points = new PointsAdd();
if (isset($_POST['submit'])) {
	$points->setEnteredBy($_SESSION['driver_id']);
	$points->getData();
	$validate = $points->validateData();
	if ($validate) $insertMessages = $points->insertData();
}
?>

<style type="text/css">
#emailBody {
	margin-top: 10px;
}

#emailDriver {
	display: none;
}

div, table, select, option, input, textarea {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 10px;
}

ul, li {
	margin: 0;
	padding: 0;
	list-style: none;
}


.error {
	color: #CC0000;
	margin-bottom: 20px;
}
</style>
<?
$points->displayActiveDriverJavascript();
?>
<script type="text/javascript">

function totalDriverPoints(id){
	single = document.forms[0].elements['points[' + id + ']'].value;
	double = document.forms[0].elements['doublePoints[' + id + ']'].value;
	triple = document.forms[0].elements['triplePoints[' + id + ']'].value;
	quadruple = document.forms[0].elements['quadruplePoints[' + id + ']'].value;
	
	trId = "row" + id;
	
	if (isNaN(single) || isNaN(double) || isNaN(triple) || isNaN(quadruple)){
		document.getElementById(trId).style.backgroundColor = "FFCCCC";
	} else {
		document.getElementById(trId).style.backgroundColor = "FFFFFF";
	}
	
	if (!(single == "" && double == "" && triple == "" && quadruple == "")){
		if (!isNaN(single) && single != "") single = single * 1;
		else single = 0;
	
		if (!isNaN(double) && double != "") double = 2 * double;
		else double = 0;
		
		if (!isNaN(triple) && triple != "") triple = 3 * triple;
		else triple = 0;
		
		if (!isNaN(quadruple) && quadruple != "") quadruple = 4 * quadruple;
		else quadruple = 0;

		totalPoints = (single + double + triple + quadruple);
		spanID = "totalPoints" + id;

		document.getElementById(spanID).innerHTML = totalPoints;
	}
}

function showEmailField(){
	if (document.forms[0].sendEmail.checked == true || document.forms[0].sendMessage.checked == true)
		document.getElementById("emailDriver").style.display = "block";
	else
		document.getElementById("emailDriver").style.display = "none";
}

function getDriverName(){
	driverid = document.forms[0].driver.value;
	return drivers[driverid];
}

function getDriverPoints(){
	return document.forms[0].points.value;
}
</script>
<body>
<center>
<form action="points_add.php" method="post">
<?
if ($points->getErrors()) {
	echo "<div class=\"error\">";
	echo $points->showErrors();
	echo "</div>";
}
if ($insertMessages) {
	echo "<div class=\"error\">";
	echo $insertMessages;
	echo "</div>";
}
?>

<div>
<table border="0" cellspacing="0" cellpadding="2" border="1">
<tr>
	<td align="right">Driver: </td>
	<td><? $points->displayActiveDriverList($points->getDriverID()); ?></td>
</tr>
<tr>
	<td valign="top" align="right">Reason: </td>
	<td><textarea rows="3" cols="30" name="reason"><?php echo $points->getReason(); ?></textarea>
</tr>
<tr>
	<td align="right">Points: </td>
	<td><input type="text" name="points" size="15" value="<?php echo $points->getPoints(); ?>" onClick="this.select()" /> <img src="images/questionmark.gif" align="absmiddle" onMouseOver="this.T_WIDTH=250; this.T_TITLE='Points'; return escape('It is <u>not</u> necessary to enter a plus sign (+) when increasing a driver\'s points (ex: +10.75), however, when decreasing a driver\'s points, you <b>must</b> enter a negative sign (ex: -15.25).')" /></td>
</tr>
<tr>
	<td align="right"><input type="checkbox" name="resetFields" value="1"<?php echo $points->getResetFields() ?> /></td>
	<td>Reset fields after submit? <img src="images/questionmark.gif" align="absbottom" onMouseOver="this.T_WIDTH=250; this.T_TITLE='Reset Fields'; return escape('If this field is checked, all of the fields will be cleared after the form is submitted. With the box unchecked, all of the data will remain in the fields for the next adjustment. This is useful, for example, when adding multiple happy write ups and the only difference is the drivers name.')" /></td>
</tr>
<tr>
	<td align="right"><input type="checkbox" name="sendMessage" value="1" onClick="showEmailField()"<?php echo $points->getSendMessage(); ?> /></td>
	<td>Send message to driver? <img src="images/questionmark.gif" align="absbottom" onMouseOver="this.T_WIDTH=250; this.T_TITLE='Send Message to Driver'; return escape('This will send a message to the driver, which will be visible via Message Center on the main page.')" /></td>
</tr>
<tr>
	<td  align="right"><input type="checkbox" name="sendEmail" onClick="showEmailField()" value="1"<?php echo $points->getSendEmail(); ?> /></td>
	<td>Send email to driver?</td>
</tr>
</table>
<div id="emailDriver">
Subject: <input type="text" name="emailSubject" size="30" value="<?php echo $points->getSubject();?>" /><br>
<textarea name="emailBody" id="emailBody" rows="8" cols="80"><?php echo $points->getBody(); ?></textarea>
</div>
</div>
<input type="submit" name="submit" value="Submit" />
</form>
<script type="text/javascript">
getDriverName();
showEmailField();
</script>
<script language="JavaScript" type="text/javascript" src="tooltip.js"></script>
</center>
</body>